﻿using CleanArchitecture.Infrastructure.Entities;
using Microsoft.AspNetCore.Mvc.Rendering;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace CleanArchitecture.Infrastructure.Models.SystemManage
{
    /// <summary>
    /// Represents a news item model
    /// </summary>
    public partial class SystemModuleModel : BaseEntityModel
    {
        #region Fields
        public IList<SelectListItem> AvailableModuleTypes { get; set; }
        #endregion
        #region Ctor
        public SystemModuleModel()
        {
            IsActive = EntityEnumConfig.YesorNo.YES;
            AvailableModuleTypes = new List<SelectListItem>()
            {
                new SelectListItem("根节点", nameof(EntityEnumConfig.SysModuleType.Root), true),
                new SelectListItem("顶部分类导航", nameof(EntityEnumConfig.SysModuleType.TopNaviMenu), false),
                new SelectListItem("左部分类导航", nameof(EntityEnumConfig.SysModuleType.LeftNaviMenu), false),
                new SelectListItem("系统模块", nameof(EntityEnumConfig.SysModuleType.ModulePage), false),
            };
        }
        #endregion
        #region Properties
        public EntityEnumConfig.SysModuleType ModuleType { get; set; }
        [DisplayName("系统模块类型")]
        public string ModuleTypeDisplay { 
            get 
            {
                var moduleType = AvailableModuleTypes.FirstOrDefault(t => t.Value == this.ModuleType.ToString());
                return moduleType == null ? string.Empty : moduleType.Text;
            }
        }
        [DisplayName("系统模块名称")]
        public string ModuleName { get; set; }
        [DisplayName("显示名称")]
        public string DisplayName { get; set; }
        public int ParentId { get; set; }
        [DisplayName("所属父级")]
        public string ParentIdDisplay { get; set; }
        public string IconText { get; set; }
        [DisplayName("选择图标")]
        public string IconCssClass { get; set; }
        [DisplayName("Url地址")]
        public string UrlRoute { get; set; }
        [DisplayName("状态")]
        public EntityEnumConfig.YesorNo IsActive { get; set; }
        [DisplayName("排序")]
        public int DisplayOrder { get; set; }
        [DisplayName("新窗口打开")]
        public EntityEnumConfig.YesorNo OpenOnNewWindow { get; set; }
        /// <summary>
        /// AssignedButtons 决定系统模块有哪些可操作的按钮
        /// </summary>
        public List<int> ModuleAssignedButtons { get; set; }

        public Dictionary<int, string> ModuleAssignedButtonsDic { get; set; }
        /// <summary>
        /// AuthorizedButtons决定角色对应的系统模块所分配的操作按钮是否有操作权限
        /// </summary>
        public List<int> ModuleAuthorizedButtons { get; set; }
        [DisplayName("模块按钮")]
        public string ModuleAssignedButtonNames { get; set; }
        #endregion
    }
}
